package org.wxd.category.engine;

import com.alibaba.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wxd.category.api.dto.CategoryGetRequest;
import org.wxd.category.api.dto.CategoryRecord;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.wxd.category.api.CategoryQueryService;
import org.wxd.category.spi.Category;

import javax.annotation.Resource;

/**
 * Created by wangxd on 2015/11/14.
 */
@Service(version = "1.0.0")
public class CategoryQueryServiceImpl implements CategoryQueryService{
    private static Logger logger = LoggerFactory.getLogger(CategoryQueryServiceImpl.class);
    @Resource
    private MongoTemplate mongoOps;

    public CategoryRecord get(CategoryGetRequest request) {
        Category category = mongoOps.findOne(Query.query(Criteria.where("_id").is(request.id())), Category.class);
        return category == null ? null : CategoryHelper.asCategoryRecord(category);
    }
}
